package com.zhentao.interceptor;

import com.zhentao.model.user.pojo.ApUser;
import com.zhentao.utils.common.AppUserThreadLocalUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class AppTokenInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        if(uri.contains("/login")){
            return true;
        }
        String userId = request.getHeader("appUserId");
        if(userId != null){
//      需要在业务中使用
            ApUser apUser=new ApUser();
            apUser.setId(Integer.valueOf(userId));
            AppUserThreadLocalUtil.setUser(apUser);
        }
        return true;
    }

    @Override
    public void postHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
